﻿using System;
using System.IO;
using System.Text;

namespace OpenReflect.Common
{
	public class CodeWriter : TextWriter
	{
		private const string INDENTCHARACTER = "\t";

		public CodeWriter(TextWriter innerWriter)
		{
			InnerWriter = innerWriter;
		}

		public CodeWriter()
			: this(new StringWriter())
		{
		}

		public TextWriter InnerWriter { get; private set; }
		public int CurrentDepth { get; protected set; }

		public override Encoding Encoding
		{
			get { throw new NotImplementedException(); }
		}

		public override void WriteLine()
		{
			InnerWriter.WriteLine();
			for (int i = 0; i < CurrentDepth; i++)
			{
				InnerWriter.Write(INDENTCHARACTER);
			}
		}

		public override void Write(string value)
		{
			InnerWriter.Write(value);
		}

		public void IncreaseIndent()
		{
			CurrentDepth++;
		}

		public void DecreaseIndent()
		{
			CurrentDepth--;
		}
	}
}